package com.hung.trade.order.api;

import com.hung.trade.common.api.IOrderApi;
import com.hung.trade.common.constants.TradeEnums;
import com.hung.trade.common.protocol.order.ConfirmOrderReq;
import com.hung.trade.common.protocol.order.ConfirmOrderResp;
import com.hung.trade.order.services.IOrderService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

/**
 * @author hungki
 * @createTime 2018-10-09 上午 1:51
 */
@Controller
public class OrderApiImpl implements IOrderApi {
    @Autowired
    private IOrderService iOrderService;
    @Override
    @RequestMapping(value = "/confirmOrder",method = RequestMethod.POST)
    @ResponseBody
    public ConfirmOrderResp confirmOrder(@RequestBody ConfirmOrderReq confirmOrderReq) {
        System.out.println("confirmOrderReq = " + confirmOrderReq);
        try {
            return iOrderService.confirmOrder(confirmOrderReq);
        }catch (Exception e){
            e.printStackTrace();
            ConfirmOrderResp resp =new ConfirmOrderResp();
            resp.setRetInfo(TradeEnums.RetEnum.FAIL.getDesc()+":"+e.getMessage());
            resp.setRetCode(TradeEnums.RetEnum.FAIL.getCode());
            return resp;
        }
    }
}
